/**
 * ReverseLinkedList.java created by zhangzhidong 
 * at 下午2:27:10 2016年4月13日
 */
package algorithm.CIG.linkedlist;

/**
 * @author zhangzhidong
 *
 */
import static java.lang.System.out;

import algorithm.CIG.base.LinkedListBase;
import algorithm.CIG.base.Node;
import algorithm.CIG.base.Visit;
public class ReverseLinkedList  extends LinkedListBase{
	public static void main(String args[]){
		Node head = generateNode(10);
		travseList(head,new VisitByPrint());
		head = reverse(head);
		out.println();
		travseList(head,new VisitByPrint());
		
	}
	
	public static Node reverse(Node head){
		if (head==null) return head;
		if (head.next==null) return head;
		Node cur = head;
		Node pre = null;
		Node next = null;
		while(cur != null){
			next = cur.next;
			cur.next =  pre;
			pre = cur;
			cur = next;
		}
		
		return pre;
		
		
	}
	
}
